package com.xxx.string;

import java.net.SocketTimeoutException;

/**
 * @version v1.0
 * @Description:
 * @Author zhanzhongxin
 * @Date 2021/7/19 10:22
 * @Copyright 博为峰
 */
public class StringDemo02 {
    public static void main(String[] args) {
        /*
           jdk8: String底层数据结构是字符数组
           查询:
           判断:
           转换:
         */
//        m1();
//        test01();
//        m2();

        String s = " 张三,李四,王五 ";
//        System.out.println(s.trim());
        String s1 = s.trim().concat(",赵六");
//        System.out.println("s1 = " + s1);
        String[] arr = s.trim().concat(",赵六").split(",");
//        System.out.println(arr);
        for (String s2 : arr) {
//            System.out.println("s2 = " + s2);
        }
//        System.out.println(s.toString());
        System.out.println(s.trim().replace(",",";"));

    }

    public static void m2() {
        String s = "abc";
        System.out.println(s.equals("ABC"));
//        System.out.println(s.contains("ab"));
//        System.out.println(s.startsWith("abc"));
//        System.out.println(s.endsWith("abc"));
        System.out.println(s.equalsIgnoreCase("ABC"));
    }

    public static void test01() {
        String s1 = "khlfsahladfhjadgkljadslfhsadfhsfdlkjsaklfhsadladsj";
        String s2 = "fh";
        int count = 0;
        int index = 0;
//        while ((index = s1.indexOf(s2)) != -1) {
//            s1 = s1.substring(index + s2.length());
//            count++;
//        }

        while ((index = s1.indexOf(s2, index)) != -1) {
//            s1 = s1.substring(index + s2.length());
            index = index + s2.length();
            count++;
        }
        System.out.println("count = " + count);
    }


    public static void m1() {
        String s = "abcdefghijklmn";
        System.out.println(s.length());//长度
        System.out.println(s.charAt(3));//根据下标返回对应的字符
        System.out.println(s.indexOf("d"));//根据字符返回对应的下标，如果没找到返回-1，如果有多个返回第一个字符对应的下标
        System.out.println(s.indexOf("d", 6));
        System.out.println(s.lastIndexOf("d"));
        System.out.println(s.substring(3, 6));//包含头部字符不包含尾部字符
        System.out.println(s.substring(3));
    }
    /*
        两个字符串中最大相同的子串
       "klhfsahladfhjkadgkljadslfhsadfhsfdlkjsaklfhjsadladsj"  "dfufhjkmnopdf"
     */
}
